package cn.com.dcsgo.library.client.domain.vo;

import cn.com.dcsgo.library.client.domain.po.BorrowRecord;
import cn.com.dcsgo.library.client.enums.BookStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Dcsgo
 * @since 2024/9/4 11:49
 */
@Data
@ApiModel(description = "图书复本详情")
@AllArgsConstructor
@NoArgsConstructor
public class BookCopiesVO {
    @ApiModelProperty("复本编号")
    private Long copyId;

    @ApiModelProperty("借阅状态")
    private BookStatus status;

    public static List<BookCopiesVO> ofBorrowRecords(List<BorrowRecord> borrowRecords) {
        List<BookCopiesVO> copiesVo = new ArrayList<>();
        for (BorrowRecord record : borrowRecords) {
            copiesVo.add(new BookCopiesVO(record.getBookCopiesId(), BookStatus.ofValue(record.getStatus())));
        }
        return copiesVo;
    }

    public static List<BookCopiesVO> ofCopiesIds(List<Long> copiesIds) {
        List<BookCopiesVO> copiesVo = new ArrayList<>();
        for (Long copyId : copiesIds) {
            copiesVo.add(new BookCopiesVO(copyId));
        }
        return copiesVo;
    }

    public BookCopiesVO(Long copyId) {
        this.copyId = copyId;
        this.status = BookStatus.IN_PAVILION;
    }
}
